package com.hyt.it.ogt.ks.service.canal;

import java.util.List;
import java.util.Objects;

import com.alibaba.otter.canal.protocol.CanalEntry;

/**
 * <p>
 * canal监听的表定义的通用方法
 * </p>
 *
 * @author zhoumioa
 * @since 2022-11-09
 */
public interface CanalTableChangeHandlerService  {
	
	void handle(List<CanalEntry.Column> beforeColumns, List<CanalEntry.Column> afterColumns, String dbName, String tableName, CanalEntry.EventType eventType, long timestamp );
    
	void insert(List<CanalEntry.Column> beforeColumns, List<CanalEntry.Column> afterColumns, String dbName, String tableName, CanalEntry.EventType eventType, long timestamp );
    
    void delete(List<CanalEntry.Column> beforeColumns, List<CanalEntry.Column> afterColumns, String dbName, String tableName, CanalEntry.EventType eventType, long timestamp );
    
    void update(List<CanalEntry.Column> beforeColumns, List<CanalEntry.Column> afterColumns, String dbName, String tableName, CanalEntry.EventType eventType, long timestamp );

    default String getFieldValue(List<CanalEntry.Column> rowData, String fieldName) {
        return rowData.stream()
                .filter(column -> Objects.equals(column.getName(), fieldName))
                .findAny().orElseThrow(() -> new IllegalArgumentException(fieldName + "：没有找到！！！")).getValue();
    }

    String getHandleTableName();

}
